package com.atguigu.tingshu.order.config;

import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

import java.util.HashMap;
import java.util.Map;

/**
 * @author codingyz
 * @Description
 * @date 2025/3/30 18:36
 * @Version 1.0
 */
//@Configuration
//@Order(5)
public class RabbitAutoConfiguration {

    /**
     * 创建延迟队列交换机
     */
    @Bean
    public CustomExchange customExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(MqConst.EXCHANGE_CANCEL_ORDER, "x-delayed-type", true, false, args);
    }

    /**
     * 创建队列
     */
    @Bean
    public Queue delayQueue() {
        return new Queue(MqConst.QUEUE_CANCEL_ORDER, true, false, false);
    }

    /**
     * 绑定队列和交换机
     */
    @Bean
    public Binding delayBinding(CustomExchange customExchange, Queue delayQueue) {
        return BindingBuilder.bind(delayQueue).to(customExchange).with(MqConst.ROUTING_CANCEL_ORDER).noargs();
    }
}
